//
//  SYdaTeViewController.m
//  KCFurProject
//
//  Created by ios程序员 on 15/11/24.
//  Copyright © 2015年 ios程序员. All rights reserved.
//

#import "SYdaTeViewController.h"



@interface SYdaTeViewController ()

@property (nonatomic ,strong) UIScrollView *scrollView;
@property (nonatomic ,strong) PSXiangQingView *psView;//详情View;
@property (nonatomic ,strong) HeaderViews *headerView;
@property (nonatomic ,strong) PSXQView *psxqView;

@end

@implementation SYdaTeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithRed:228/255.0 green:229/255.0 blue:230/255.0 alpha:1];
    self.scrollView.backgroundColor = [UIColor colorWithRed:228/255.0 green:229/255.0 blue:230/255.0 alpha:1];
    // Do any additional setup after loading the view.
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
//    self.scrollView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.scrollView];
    // Do any additional setup after loading the view.
    self.edgesForExtendedLayout = UIRectEdgeNone;
    
    _scrollView.contentSize = CGSizeMake(0, 350*HEIGH);
    
    ShouyeCollecViewController *detailVC = [[ShouyeCollecViewController alloc] init];
    [self addChildViewController:detailVC];
    
    // just for force load view
    if (detailVC.view != nil) {
        _scrollView.secondScrollView = detailVC.scrollView;
    }
    [self psxiangQingViews];
    [self psxqViews];
    [self headerViewss];
    [self.psxqView.xuanZeButton addTarget:self action:@selector(xuanZeButtonClick:) forControlEvents:UIControlEventTouchUpInside];




}
//轮播图View
- (void)headerViewss
{
    self.headerView = [[HeaderViews alloc] initWithFrame:CGRectMake(0, 0, w, 200*HEIGH)];
    self.headerView.backgroundColor = [UIColor whiteColor];
    UITapGestureRecognizer *imageTap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(bigButtonTapped:)];
    self.headerView.image1.userInteractionEnabled = YES;
    [self.headerView.image1 addGestureRecognizer:imageTap1];
    UITapGestureRecognizer *imageTap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(bigButtonTapped:)];
    self.headerView.image2.userInteractionEnabled = YES;
    [self.headerView.image2 addGestureRecognizer:imageTap2];
    UITapGestureRecognizer *imageTap3 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(bigButtonTapped:)];
    self.headerView.image3.userInteractionEnabled = YES;
    [self.headerView.image3 addGestureRecognizer:imageTap3];
    
    [self.scrollView addSubview:self.headerView];
    
}
/* 详情View */
- (void)psxiangQingViews
{
    self.psView = [[PSXiangQingView alloc] initWithFrame:CGRectMake(0, 190*HEIGH, self.view.frame.size.width, 100*HEIGH)];
    UITapGestureRecognizer *tapImage = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(bigButtonTapped:)];
    self.psView.XQimageView.userInteractionEnabled = YES;
    [self.psView.XQimageView addGestureRecognizer:tapImage];
    
    [self.scrollView addSubview:self.psView];
    self.psView.backgroundColor = [UIColor whiteColor];
//    self.psView.backgroundColor = [UIColor colorWithRed:240/255.0 green:241/255.0 blue:242/255.0 alpha:1];
    
}

//放大效果
- (void)bigButtonTapped:(UITapGestureRecognizer *)sender {
    
    
//     Create image info
//        CGPoint location = [sender locationInView:self.tableView];
    //    NSIndexPath *indexPath  = [self.tableView indexPathForRowAtPoint:location];
    //
    //    UITableViewCell *cell = (UITableViewCell *)[self.tableView  cellForRowAtIndexPath:indexPath];
    
    UIImageView *imageView=(UIImageView *)[self.headerView.image1 viewWithTag:100];
    
    JTSImageInfo *imageInfo = [[JTSImageInfo alloc] init];
    imageInfo.image = imageView.image;
    imageInfo.referenceRect = imageView.frame;
    imageInfo.referenceView = imageView.superview;
    imageInfo.referenceContentMode = imageView.contentMode;
    imageInfo.referenceCornerRadius = imageView.layer.cornerRadius;
    
    //
    UILongPressGestureRecognizer *tapGesture = [[UILongPressGestureRecognizer alloc] init];
    imageView.userInteractionEnabled = YES;
    tapGesture.numberOfTapsRequired = 1;
    tapGesture.numberOfTouchesRequired = 1;
    
    [tapGesture addTarget:self action:@selector(tapSaveImageToIphone)];
    [ imageView addGestureRecognizer:tapGesture];
    
    
    
    
    // Setup view controller
    JTSImageViewController *imageViewer = [[JTSImageViewController alloc]
                                           initWithImageInfo:imageInfo
                                           mode:JTSImageViewControllerMode_Image
                                           backgroundStyle:JTSImageViewControllerBackgroundOption_Blurred];
    // Present the view controller.
    [imageViewer showFromViewController:self transition:JTSImageViewControllerTransition_FromOriginalPosition];
    
}
- (void)tapSaveImageToIphone{
    
    /**
     *  将图片保存到iPhone本地相册
     *  UIImage *image            图片对象
     *  id completionTarget       响应方法对象
     *  SEL completionSelector    方法
     *  void *contextInfo
     */
    //    UIImageWriteToSavedPhotosAlbum(self.imageView.image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
    
}

- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{
    
    if (error == nil) {
        
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"已存入手机相册" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定",  nil];
        [alert show];
        
    }else{
        
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"保存失败" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定",  nil];
        [alert show];
    }
    
}

/* 选择 拖动 */
- (void)psxqViews
{
    self.psxqView = [[PSXQView alloc] initWithFrame:CGRectMake(5, 310*HEIGH, self.view.frame.size.width-10, 25*HEIGH)];
    [self.psxqView.xuanZeButton addTarget:self action:@selector(xuanZeButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.scrollView addSubview:self.psxqView];
}

//跳转选择颜色和尺码的方法
- (void)xuanZeButtonClick:(UIButton *)button
{
    
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
